<template>
    <div ref="chart" style="width: 600px; height: 400px;"></div>
</template>

<script setup>
import { ref, onMounted, nextTick } from 'vue';
import * as echarts from 'echarts';

const chart = ref(null);
const props = defineProps({
    TargetScoreForProps: {
        type: Array,
        default: () => []
    }
})
let newData = []
const convertype = () => {
    newData = props.TargetScoreForProps.map(obj => {
        return {
            name: obj.target_name,
            value: obj.score
        };
    });
}
onMounted(() => {

    nextTick(() => {
        const myChart = echarts.init(chart.value);
        convertype()
        // console.log("newData", newData);
        let option = {
            backgroundColor: '#ecf5ff',
            title: {
                text: '课程目标占比',
                left: 'center',
                top: 20,
                textStyle: {
                    color: 'black'
                }
            },
            tooltip: {
                trigger: 'item'
            },
            visualMap: {
                show: false,
                min: 1,
                max: 100,
                inRange: {
                    colorLightness: [0, 3]
                }
            },
            series: [
                {
                    name: '课程目标',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '50%'],
                    data: newData.sort(function (a, b) {
                        return a.value - b.value;
                    }),
                    roseType: 'radius',
                    label: {
                        normal: {
                            // formatter: '{b}:{c}: ({d}%)',
                            formatter: ' ({d}%)',
                            textStyle: {
                                fontWeight: 'normal',
                                fontSize: 15
                            }
                        },
                        color: 'rgba(255, 255, 255, 0.3)'
                    },
                    labelLine: {
                        lineStyle: {
                            color: 'black'
                        },
                        smooth: 0.2,
                        length: 10,
                        length2: 20
                    },
                    itemStyle: {
                        color: '#409eff',
                        // shadowBlur: 200,
                        // shadowColor: 'rgba(0, 0, 0, 0.5)'
                    },
                    animationType: 'scale',
                    animationEasing: 'elasticOut',
                    animationDelay: function (idx) {
                        return Math.random() * 200;
                    }
                }
            ]
        };

        myChart.setOption(option);
    });
});
</script>
